﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Data.Common;
using Mocola.BLL;
using Mocola.Model;

namespace Mocola.Net.Web.ajax
{
    public partial class UpdateMFile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                MembershipCreateStatus status = new MembershipCreateStatus();
                DbTransaction transaction = Databases.MocolaNet.BeginTransaction(IsolationLevel.ReadCommitted);

                try
                {
                    int ID = Convert.ToInt32(Request.QueryString["id"]);
                    string pTid = getRequest("Tid");
                    string pEid = getRequest("Eid");
                    string pMingCheng = getRequest("MingCheng");        // 名称
                    string pWenJianHao = getRequest("WenJianHao");      // 文件号
                    string pShenQingHao = getRequest("ShenQingHao");    // 申请号
                    string pJueDingHao = getRequest("JueDingHao");      // 决定号

                    string pJiShouRiQi = getRequest("JieShouRiQi_Nian") + "-" + getRequest("JieShouRiQi_Yue") + "-" + getRequest("JieShouRiQi_Ri");      // 接收时间
                    string pFaWenRiQi = getRequest("FaWenRiQi_Nian") + "-" + getRequest("FaWenRiQi_Yue") + "-" + getRequest("FaWenRiQi_Ri");      // 发文日期

                    string pFaWenDanWei = getRequest("FaWenDanWei");        // 发文单位
                    string pShuLiang = getRequest("ShuLiang");              // 数量
                    string pZaiTi = getRequest("ZaiTi");                    // 载体
                    string pCaiZhi = getRequest("CaiZhi");                  // 材质
                    string pMiJi = getRequest("MiJi");                      // 密级
                    string pBaoGuanQiXian = getRequest("BaoGuanQiXian");    // 保管期限
                    string pZhuangTai = getRequest("ZhuangTai");            // 状态
                    string pBeiZhu = getRequest("BeiZhu");                  // 备注

                    bool bUpdated = Databases.MocolaNet.Update(Moc_MFilesInfo.Moc_MFiles)
                                     .AddColumn(Moc_MFilesInfo.Moc_MFiles.Name, pMingCheng)
                                     .AddColumn(Moc_MFilesInfo.Moc_MFiles.JueDingHao, pJueDingHao)
                                     .AddColumn(Moc_MFilesInfo.Moc_MFiles.WenJianHao, pWenJianHao)
                                     .AddColumn(Moc_MFilesInfo.Moc_MFiles.ShenQingHao, pShenQingHao)
                                     .AddColumn(Moc_MFilesInfo.Moc_MFiles.FaWenRiQi, pFaWenRiQi)
                                     .AddColumn(Moc_MFilesInfo.Moc_MFiles.FaWenDanWei, pFaWenDanWei)
                                     .AddColumn(Moc_MFilesInfo.Moc_MFiles.ShuLiang, pShuLiang)
                                     .AddColumn(Moc_MFilesInfo.Moc_MFiles.ZaiTi, pZaiTi)
                                     .AddColumn(Moc_MFilesInfo.Moc_MFiles.CaiZhi, pCaiZhi)
                                     .AddColumn(Moc_MFilesInfo.Moc_MFiles.MiJi, pMiJi)
                                     .AddColumn(Moc_MFilesInfo.Moc_MFiles.BaoGuanQiXian, pBaoGuanQiXian)
                                     .AddColumn(Moc_MFilesInfo.Moc_MFiles.ZhuangTai, pZhuangTai)
                        //.AddColumn(Moc_MFilesInfo.Moc_MFiles.FaQiBuMen, pFaQiBuMen)
                        //.AddColumn(Moc_MFilesInfo.Moc_MFiles.YiJiaoRen, pYiJiaoRen)
                        //.AddColumn(Moc_MFilesInfo.Moc_MFiles.JiShouRen, pJiShouRen)
                                     .AddColumn(Moc_MFilesInfo.Moc_MFiles.JieShouRiQi, pJiShouRiQi)
                                     .AddColumn(Moc_MFilesInfo.Moc_MFiles.BeiZhu, pBeiZhu)
                                     .AddColumn(Moc_MFilesInfo.Moc_MFiles.Eid, pEid)
                                     .AddColumn(Moc_MFilesInfo.Moc_MFiles.Tid, pTid)
                                     .Where(Moc_MFilesInfo.Moc_MFiles.ID == ID)
                                     .SetTransaction(transaction)
                                     .Execute() == 1;
                    if (bUpdated)
                    {
                        Response.Write("文件更新成功！");
                        status = MembershipCreateStatus.Success;
                    }
                    else
                    {
                        Response.Write("文件更新失败！");
                        status = MembershipCreateStatus.ProviderError;
                    }
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                    status = MembershipCreateStatus.ProviderError;
                }
                finally
                {
                    if (status == MembershipCreateStatus.Success)
                        transaction.Commit();
                    else
                        transaction.Rollback();
                    Databases.MocolaNet.CloseConnection(transaction);
                }
            }
        }

        private string getRequest(string pReqID)
        {
            return string.IsNullOrEmpty(Request.Form[pReqID]) ? string.Empty : Request.Form[pReqID].ToString();
        }
    }
}
